home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Think Class Libraries / WASTE TCL 2.0b2 / WASTE VA / Source / x_CApp.cp < prev    next >
Encoding:
Text File  |  1996-06-16  |  6.8 KB  |  286 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  x_CApp.cp
  3.  
  4.                 CApp "Lower-Layer" Application Class
  5.     
  6.     Copyright Â© 1996 Dan Crevier. All rights reserved.
  7.  
  8.     Generated by Visual Architectâ„¢ 10:48 AM Sun, Jun 16, 1996
  9.  
  10.     This file is rewritten each time you generate code. You should not
  11.     make changes to this file; changes should go in the CApp.cp
  12.     file, instead.
  13.  
  14.     If you want to change how Visual Architect generates this file, you can
  15.     change the template for this file. It is "_App_cp" in the Visual Architect
  16.     Templates folder.
  17.  
  18.  ******************************************************************************/
  19.  
  20. #include "x_CApp.h"
  21.  
  22. #include "CApp.h"
  23.  
  24. #include "References.h"
  25. #include "CMain.h"
  26. #include "CAbout.h"
  27. #include <CBartender.h>
  28. #include <Commands.h>
  29. #include <CDesktop.h>
  30. #include <CFile.h>
  31. #include <CFWDesktop.h>
  32. #include <CList.h>
  33. #include <Packages.h>
  34. #include <TBUtilities.h>
  35. #include <TCLForceReferences.h>
  36.  
  37. #include "CAbout.h"
  38. #include "CMain.h"
  39. #include "CVAWASTEDlgText.h"
  40. #include "CVAWASTEText.h"
  41.  
  42. extern OSType        gSignature;            /* Creator for Application's files    */
  43. extern CBartender    *gBartender;        /* Manages all menus                */
  44. extern CDesktop        *gDesktop;            /* The visible Desktop                */
  45.  
  46.     // Define symbols for commands handled by this class
  47.     // Prevents a recompile every time any command changed.
  48.  
  49. #define cmdAbout 256
  50.  
  51.  
  52. TCL_DEFINE_CLASS_M1(x_CApp, CApplication);
  53.  
  54. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  55.  
  56.  
  57. /******************************************************************************
  58.  Ix_CApp
  59.  
  60.         Initialize an Application.
  61.  ******************************************************************************/
  62.  
  63. void    x_CApp::Ix_CApp(short extraMasters, Size aRainyDayFund,
  64.                                     Size aCriticalBalance, Size aToolboxBalance)
  65.  
  66. {
  67.     IApplication(extraMasters, aRainyDayFund, aCriticalBalance, aToolboxBalance);
  68. }
  69.  
  70.  
  71. /******************************************************************************
  72.  SetUpFileParameters    {OVERRIDE}
  73.  
  74.     Specify the kinds of files your application opens
  75.  ******************************************************************************/
  76.  
  77. void x_CApp::SetUpFileParameters()
  78. {
  79.     CApplication::SetUpFileParameters();
  80.  
  81.         // File types as defined in CApp.h
  82.  
  83.     sfNumTypes = kNumFileTypes;
  84.     sfFileTypes[0] = kFileType1;
  85.     sfFileTypes[1] = kFileType2;
  86.     sfFileTypes[2] = kFileType3;
  87.     sfFileTypes[3] = kFileType4;
  88.     gSignature = 'wVAp';
  89. }
  90.  
  91.  
  92. /******************************************************************************
  93.  SetUpMenus {OVERRIDE}
  94.  
  95.         Set up the menus after first creating any floating/tearoff
  96.         windows. The latter must be done before the bartender inits.
  97.  ******************************************************************************/
  98.  
  99. void x_CApp::SetUpMenus()
  100. {
  101.  
  102.  
  103.     CApplication::SetUpMenus();
  104.  
  105. }
  106.  
  107.  
  108. /******************************************************************************
  109.  ForceClassReferences    {OVERRIDE}
  110.  
  111.     Reference classes that might do object I/O.
  112.  ******************************************************************************/
  113.  
  114. void x_CApp::ForceClassReferences(void)
  115.  
  116. {
  117.     CApplication::ForceClassReferences();
  118.  
  119.                                             /* From References.c            */
  120.     ReferenceStdClasses();                    /*     See template file Ref        */
  121.     
  122.     TCL_FORCE_REFERENCE(CVAWASTEDlgText);
  123.     TCL_FORCE_REFERENCE(CVAWASTEText);
  124. }
  125.  
  126.  
  127. /**** C O M M A N D   M E T H O D S ****/
  128.  
  129.  
  130. /******************************************************************************
  131.  DoCommand    {OVERRIDE}
  132.  
  133.     Handle application commands
  134.  ******************************************************************************/
  135.  
  136. void x_CApp::DoCommand(long theCommand)
  137.  
  138. {
  139.     switch (theCommand)
  140.     {
  141.         case cmdAbout:
  142.             DoCmdAbout();
  143.             break;
  144.  
  145.         default:
  146.             CApplication::DoCommand(theCommand);
  147.             break;
  148.     }
  149. }
  150.  
  151.  
  152. /******************************************************************************
  153.  UpdateMenus {OVERRIDE}
  154.  
  155.         Enable menus which generate commands handled by this class.
  156.  ******************************************************************************/
  157.  
  158. void x_CApp::UpdateMenus()
  159.  
  160. {
  161.     CApplication::UpdateMenus();
  162.  
  163.     gBartender->EnableCmd(cmdAbout);
  164. }
  165.  
  166.  
  167. /******************************************************************************
  168.  DoCmdAbout
  169.  
  170.         Respond to cmdAbout command.
  171.  ******************************************************************************/
  172.  
  173. void x_CApp::DoCmdAbout()
  174.  
  175. {
  176.     CAbout        *alert;
  177.     
  178.           // Respond to command by opening a alert
  179.  
  180.     alert = TCL_NEW(CAbout,());
  181.     alert->ICAbout(this);
  182.  
  183.     alert->DoModalDialog(cmdNull);    /* cmdNull because dialog already knows    */
  184.     TCLForgetObject(alert);
  185. }
  186.  
  187.  
  188. /**** D O C U M E N T   M E T H O D S ****/
  189.  
  190.  
  191. /******************************************************************************
  192.  CreateDocument    {OVERRIDE}
  193.  
  194.     Make a new document when user chooses New from file menu.
  195.     This method is entirely generic except for the document class.
  196.  ******************************************************************************/
  197.  
  198. void x_CApp::CreateDocument()
  199.  
  200. {
  201.     CDocument    *volatile theDocument = NULL;
  202.  
  203.     theDocument = TCL_NEW(CMain,());
  204.     try_
  205.     {
  206.         ((CMain*) theDocument)->ICMain();
  207.         theDocument->NewFile();
  208.     }
  209.     catch_all_()
  210.     {
  211.         TCLForgetObject(theDocument);
  212.         throw_same_();
  213.     }
  214.     end_try_
  215. }
  216.  
  217.  
  218. /******************************************************************************
  219.  OpenDocument    {OVERRIDE}
  220.  
  221.     Open a document when user chooses Open from file menu.
  222.     For multiple document types, this method assumes that each
  223.     document is associated with a single file type. 
  224.  ******************************************************************************/
  225.  
  226. void x_CApp::OpenDocument(SFReply *macSFReply)
  227.  
  228. {
  229.     CDocument    *volatile theDocument = NULL;
  230.  
  231.     theDocument = TCL_NEW(CMain,());
  232.     try_
  233.     {
  234.         ((CMain*) theDocument)->ICMain();
  235.         theDocument->OpenFile(macSFReply);
  236.     }
  237.     catch_all_()
  238.     {
  239.         TCLForgetObject(theDocument);
  240.         throw_same_();
  241.     }
  242.     end_try_
  243. }
  244.  
  245.  
  246.  
  247.  
  248. /******************************************************************************
  249.  FileAlreadyOpen
  250.  
  251.     If file already in use return TRUE and bring owning document's
  252.     window to the foreground.  Sent from document before opening.
  253.  ******************************************************************************/
  254.  
  255.     static Boolean EqualFile(CDirector *obj, long param)
  256.     {
  257.         FSSpec        theFileSpec;
  258.         CFile        *theFile;
  259.         FSSpec        *theParam = (FSSpec*) param;
  260.  
  261.         if (member(obj, CDocument))
  262.         {
  263.             theFile = ((CDocument*)obj)->itsFile;
  264.             if (theFile == NULL)
  265.                 return FALSE;
  266.             theFile->GetFSSpec(&theFileSpec);
  267.             return theFileSpec.vRefNum == theParam->vRefNum
  268.                 && theFileSpec.parID == theParam->parID
  269.                 && !IUEqualString(theFileSpec.name, theParam->name);
  270.         }
  271.         return FALSE;
  272.     }
  273.  
  274. Boolean x_CApp::FileAlreadyOpen(
  275.     FSSpec        *fileSpec)
  276.  
  277. {
  278.     CDirector    *theDirector = NULL;
  279.  
  280.     if (itsDirectors)                        /* Search for matching file        */
  281.         theDirector = (CDirector*) itsDirectors->FindItem1(EqualFile, (long) fileSpec);
  282.     if (theDirector)                        /* If find one, bring to front    */
  283.         theDirector->GetWindow()->Select();
  284.     return theDirector != NULL;                /* Tell caller                    */
  285. }
  286.